<template>
    <div class="app-container customer-div" style="min-height:calc(100vh - 105px)">
        <el-menu :default-active="listQuery.planState" class="el-menu-demo" mode="horizontal" @select="handleSelect">
            <el-menu-item index="">全部</el-menu-item>
            <el-menu-item index="0">待物流发货</el-menu-item>
            <el-menu-item index="10">发货中</el-menu-item>
            <el-menu-item index="25">待提货</el-menu-item>
            <el-menu-item index="30">待出库</el-menu-item>
            <el-menu-item index="40">已出库</el-menu-item>
            <el-menu-item index="5">已取消</el-menu-item>
        </el-menu>

        <!--数据列表-->
        <div class="table-container">
           <vxe-grid ref='xGrid' v-bind="gridOptions" size="mini" :loading="listLoading">
             <template #form>
               <div>
                 <!--搜索-->
                 <el-form :inline="true" :model="listQuery" size="mini" label-width="100px">
                   <el-form-item label="销售订单号：" >
                     <el-input v-model="listQuery.orderSn"></el-input>
                   </el-form-item>
                   <el-form-item label="客户名称：" >
                      <el-select
                        clearable
                        v-model="listQuery.customerId"
                        filterable
                        remote
                        reserve-keyword
                        placeholder="请输入关键词"
                        :remote-method="querySearch">
                        <el-option
                          v-for="item in querySearchList"
                          :key="item.customerId"
                          :label="item.customerName"
                          :value="item.customerId">
                        </el-option>
                      </el-select>
                   </el-form-item>
                   <el-form-item label="客户编号：">
                     <el-input v-model="listQuery.customerNumber"></el-input>

                   </el-form-item>
                   <el-form-item label="商品信息">
                     <el-select
                       v-model="listQuery.goodsKingId"
                       filterable
                       remote
                       clearable
                       placeholder="请输入关键词"
                       :remote-method="((val)=>{remoteMethod(val)})"
                       :loading="goodsLoading">
                       <el-option
                         v-for="item in list"
                         :key="item.kingGoodsId"
                         :label="item | fifitem"
                         :value="item.kingGoodsId">
                       </el-option>
                     </el-select>
                   </el-form-item>
                   <el-form-item label="业务员：" v-if="formPage != 'sale'">
                     <el-select v-model="listQuery.orderUserId" filterable placeholder="请选择" clearable>
                       <el-option
                         v-for="item in userOptionList"
                         :key="item.userId"
                         :label="item.userName"
                         :value="item.userId">
                       </el-option>
                     </el-select>
                   </el-form-item>
                   <el-form-item label="提货日期：">
                     <el-date-picker
                       :default-time="['00:00:00']"
                       v-model="listQuery.date"
                       type="daterange"
                       format="yyyy 年 MM 月 dd 日"
                       value-format="yyyy-MM-dd"
                       range-separator="至"
                       start-placeholder="开始日期"
                       end-placeholder="结束日期">
                     </el-date-picker>
                   </el-form-item>

                   <el-form-item label="发货类型：" >
                     <el-select v-model="listQuery.goodsSendType" filterable placeholder="请选择" clearable>
                       <el-option
                         key="公司发货"
                         label="公司发货"
                         value="公司发货">
                       </el-option>
                       <el-option
                         key="采购发货"
                         label="采购发货"
                         value="采购发货">
                       </el-option>
                       <el-option
                         key="客户自提"
                         label="客户自提"
                         value="客户自提">
                       </el-option>
                     </el-select>
                   </el-form-item>
                   <el-form-item label="提货仓库">
                     <el-input v-model="listQuery.takeWarehouse"></el-input>
                   </el-form-item>
                   <el-form-item label="创建人：">
                     <el-select v-model="listQuery.planUserId" filterable placeholder="请选择" clearable>
                       <el-option
                         v-for="item in userOptionList"
                         :key="item.userId"
                         :label="item.userName"
                         :value="item.userId">
                       </el-option>
                     </el-select>
                   </el-form-item>

                   <el-form-item label="采购合同号：">
                     <el-input v-model="listQuery.purchaseOrderSn"></el-input>
                   </el-form-item>

                   <el-form-item label="排货类型：">
                     <el-select v-model="listQuery.billTypeList" placeholder="请选择" clearable multiple>
                       <el-option
                         v-for="item in billTypeList"
                         :key="item.key"
                         :label="item.name"
                         :value="item.key">
                       </el-option>
                     </el-select>
                   </el-form-item>


                   <el-form-item>
                     <el-button
                       @click="handleSearchList()"
                       type="primary">
                       查询
                     </el-button>
                   </el-form-item>
                 </el-form>
               </div>
             </template>
             <template #pager>
               <div style="overflow: hidden">
                 <div class="pagination-container">
                   <el-pagination
                     background
                     @size-change="handleSizeChange"
                     @current-change="handleCurrentChange"
                     layout="total, sizes,prev, pager, next,jumper"
                     :current-page.sync="listQuery.pageNum"
                     :page-size="listQuery.pageSize"
                     :page-sizes="[10,15,20,50,100,200]"
                     :total="count">
                   </el-pagination>
                 </div>
               </div>

             </template>
             <template #for_default="{ row, rowIndex }">
               <div v-for="(item,index) in row.billGoods" class="mergeDiv" style="text-align: left" :style="{'padding-top':index == 0 ? '0' : '13px','padding-bottom':index <row.billGoods.length - 1 ? '13px' : '0px' }">
                 <span style="vertical-align: middle">{{item.goodsName}} / {{item.goodsSn}} / {{item.goodsNum}}</span>
                 <el-tooltip class="item" effect="dark" :content="item.changeTip" placement="right-end" style="display: inline-block" v-if="item.changeTip != ''">
                   <span style="vertical-align:middle;display: inline-block;background: #409EFF;color: rgb(255, 255, 255);cursor: pointer;padding: 0 2px;line-height: 16px;border-radius: 5px;">变</span>
                 </el-tooltip>
               </div>
             </template>
             <template #for_default2="{ row, rowIndex }">
               <div v-for="(item,index) in row.billGoods" class="mergeDiv" :style="{'padding-top':index == 0 ? '0' : '13px','padding-bottom':index <row.billGoods.length - 1 ? '13px' : '0px' }">{{item.goodsRemark}}</div>
             </template>
             <template #for_default5="{ row, rowIndex }">
               <div v-for="(item,index) in row.billGoods" class="mergeDiv" :style="{'padding-top':index == 0 ? '0' : '13px','padding-bottom':index <row.billGoods.length - 1 ? '13px' : '0px' }">{{item.inquiryRemark}}</div>
             </template>
             <template #for_default3="{ row, rowIndex }">
               <div>{{row.receiverName}}</div>
               <div>{{row.receiverMobile}}</div>
               <div>{{row.receiveAddress}}</div>
             </template>
             <template #for_default4="{row,rowIndex}">
               <span>{{row.billSn}}</span>
               <el-tag size="mini" effect="dark" type="danger" v-if="row.isSure==0">不确定</el-tag>
               <el-tag size="mini" effect="dark"  v-if="row.isNeedDriverUnload==1">卸</el-tag>
             </template>
             <template #for_default6="{ row, rowIndex }">
               <div>{{row.driverName}}</div>
               <div>{{row.driverMobile}}</div>
               <div>{{row.driverTruckNo}}</div>
             </template>
             <template #for_default7="{ row, rowIndex }">
                <el-button type="text" size="small" @click="toInfo(row)">查看</el-button>
               <span v-if="formPage!='sale'">
                  <el-button type="text" size="small" v-if="row.planState == 25"  @click="confirmTiHuo(row)">确认提货</el-button>
                  <span v-if="row.billType == 'saleOrder'">
                   <span v-if="row.sendType == '运联发货'">
                      <el-button type="text" size="small" v-if="row.planState == 0" @click="showDialogVisible4(row,'物流确认发货')">物流确认发货</el-button>
                      <el-button type="text" size="small" v-if="row.planState == 10"  @click="cancelDeliver(row)">取消发货</el-button>
                      <el-button type="text" size="small" v-if="row.planState == 30 && row.isNeedCheck==1" @click="showDialogVisible(row)">确认出库</el-button>
                      <el-button type="text" size="small" v-if="row.planState == 25 || row.planState == 30 || row.planState == 40" @click="showPrint(row)">打印单据</el-button>
                   </span>
                  <span v-if="row.sendType == '工厂发货'">
                      <el-button type="text" size="small" v-if="row.planState == 30&& row.isNeedCheck==1" @click="showDialogVisible(row)">确认出库</el-button>
                      <el-button type="text" size="small" v-if="row.planState == 25 || row.planState == 30 || row.planState == 40" @click="showPrint(row)">打印单据</el-button>
                  </span>
                  <span v-if="row.sendType == '自提'">
                      <el-button type="text" size="small" v-if="row.planState == 30 && row.isNeedCheck==1" @click="showDialogVisible(row)">确认出库</el-button>
                      <el-button type="text" size="small" v-if="row.planState == 25 || row.planState == 30 || row.planState == 40" @click="showPrint(row)">打印单据</el-button>
                  </span>
                </span>
                  <span v-if="row.billType == 'purchaseOrder'">
                      <el-button type="text" size="small" v-if="row.planState == 0" @click="showDialogVisible4(row,'物流确认发货')">物流确认发货</el-button>
                      <el-button type="text" size="small" v-if="row.planState == 10"  @click="cancelDeliver(row)">取消发货</el-button>
                      <el-button type="text" size="small" v-if="row.planState == 30" @click="confirmWarehousing(row)">确认入库</el-button>
                      <el-button type="text" size="small" v-if="row.planState == 25 || row.planState == 30 || row.planState == 40" @click="showPrint(row)">打印单据</el-button>
               </span>
               </span>

               <span v-else>
                  <span v-if="row.billType == 'saleOrder'">
                   <span v-if="row.sendType == '运联发货'">
                      <el-button type="text" size="small" v-if="row.planState == 25 || row.planState == 30 || row.planState == 40" @click="showPrint(row)">打印单据</el-button>
                   </span>
                  <span v-if="row.sendType == '工厂发货'">
                      <el-button type="text" size="small" v-if="row.planState == 25 || row.planState == 30 || row.planState == 40" @click="showPrint(row)">打印单据</el-button>
                  </span>
                  <span v-if="row.sendType == '自提'">
                      <el-button type="text" size="small" v-if="row.planState == 25 || row.planState == 30 || row.planState == 40" @click="showPrint(row)">打印单据</el-button>
                  </span>
                </span>
                  <span v-if="row.billType == 'purchaseOrder'">
                      <el-button type="text" size="small" v-if="row.planState == 25 || row.planState == 30 || row.planState == 40" @click="showPrint(row)">打印单据</el-button>
               </span>
               </span>

             </template>
             <template #for_default8="{ row, rowIndex }">
               <span>{{row.saleOrderSn}}</span><span style="margin-left:5px;background: red;font-size:12px;color:#fff;padding:0 2px;line-height:18px;border-radius: 4px;display: inline-block" v-if="row.customerUnSendNum > 0">拼</span>
             </template>
             <template #customerName_default="{ row, rowIndex }">
               <div style="white-space: normal;">{{row.customerNumber }}</div>
               <!--是否有权限-->
               <div style="white-space: normal;">{{row.customerName}}</div>
             </template>

             <template #for_default9="{ row, rowIndex }">
               <div v-for="(item,index) in row.receivedPicUrl" :key="index" style="color: rgb(64, 158, 255);cursor: pointer;  white-space: nowrap;overflow: hidden;text-overflow: ellipsis;" @click="openUrl(item)">{{item}}</div>
<!--               <el-image v-for="(item,index) in row.receivedPicUrl" :key="index" :src="item" :preview-src-list="row.receivedPicUrl" style="width:50px;height:50px;float: left;margin-right:5px;"></el-image>-->
             </template>

             <template #for_default10="{ row, rowIndex }">
                 <div :style="{color:row.orderRemark.indexOf('卸货前付清') == -1 ? '#606266' : 'red'}">{{row.orderRemark}}</div>
             </template>
           </vxe-grid>
        </div>

        <!--确认出库-->
        <confirmOut ref="confirmOut" @refresh="refresh"></confirmOut>

        <!--取消排货-->
        <cancelShipment ref="cancelShipment" @refresh="refresh"></cancelShipment>

        <!--物流确认发货-->
        <logisticsConfirmsDelivery ref="logisticsConfirmsDelivery" @refresh="refresh"></logisticsConfirmsDelivery>

        <!--详情-->
        <el-drawer
          size="1000px"
          :modal="false"
          title="排货详情"
          :visible.sync="drawer"
          direction="rtl">
          <dischargingInfo ref="dischargingInfo"
                           userType="deliver"
                           @showSendGoods="showSendGoods"
                           @showDialogVisible4="showDialogVisible4"
                           @showCancelForm="showCancelForm"
                           @cancelDeliver="cancelDeliver"
                           @showPrint="showPrint"
                           @showDialogVisible="showDialogVisible"
                           @confirmWarehousing="confirmWarehousing"
                           @refresh="refresh"
          ></dischargingInfo>
        </el-drawer>

        <!--打印弹窗-->
        <printdischarging ref="printdischarging"></printdischarging>

    </div>
</template>
<script>
    import {getCustomerOption,getOrderUsersList,getCrmGoodsList} from '@/api/partner'
    import {planGoodsListScheduled,checkStockIn,cancelGoodsDeliver,checkBillTake} from '@/api/order'
    import {formatDate} from '@/utils/date';
    import sendGoods from '@/views/components/sendGoods';
    import sourceGoods from '@/views/components/sourceGoods'
    import dischargingInfo from '@/views/components/dischargingInfo'
    import printdischarging from '@/views/components/printdischarging'
    import cancelShipment from '@/views/components/cancelShipment'
    import confirmOut from '@/views/components/confirmOut'
    import logisticsConfirmsDelivery from '@/views/components/logisticsConfirmsDelivery'
    import store from '@/store'
    import { mapGetters } from 'vuex'
    import {getUserOption, inputDriverInfo} from "../../api/partner";
    const defaultListQuery={
      "planState"   : '',       //排货状态(0已排货，5已取消,10发货中，20待安排司机 30待出库 40已出库)
      "date"        : [], //提货日期
      "orderSn"     : "", //合同号
      "goodsKingId" : "", //商品SAPID
      "customerId"  : "",  //客户ID
      "orderUserId" : "", //业务员ID
      "purchaseOrderSn" : "", //采购单号
      "planUserId"  : "",  //创建人
      takeWarehouse:'',
      goodsSendType:'',
      isMy:0,
      billTypeList:[],
      "pageNum" : 1,      //第几页，默认1
      "pageSize" : 10 ,    //每页几条，默认10条
      customerNumber:''
    };

    export default {
        name: "index",
        data(){
            return {
                listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
                tableData: [],
                count: 0,
                listLoading: false,
                roles:store.getters.roles ? store.getters.roles : [],
                userOptionList:[],
                querySearchList:[],
                gridOptions:{
                  border: true,
                  id: 'full_edit_1',
                  align:'center',
                  rowConfig: {
                    keyField: 'billId',
                    isHover: true
                  },
                  columnConfig: {
                    resizable: true
                  },
                  customConfig: {
                    storage: true,
                  },
                  toolbarConfig: {
                    zoom: true,
                    custom: true
                  },
                  columns: [

                    {
                      field: 'billSn',
                      title: '编号',
                      width: 180,
                      slots: {
                        default: 'for_default4',
                      },

                    },
                    {
                      field: 'billType',
                      title: '排货类型',
                      width: 100,
                      formatter ({ cellValue }) {
                        if(cellValue == 'purchaseOrder'){
                          return '采购单'
                        }else if(cellValue == 'saleOrder'){
                          return '销售单'
                        }else if(cellValue == 'agentProcess'){
                          return '代加工单'
                        }
                      }
                    },
                    {
                      field: 'saleOrderSn',
                      title: '销售订单号',
                      width: 150,
                      slots: {
                        // 使用插槽模板渲染
                        default: 'for_default8',
                      }
                    },
                    {
                      field: "customerNumber",
                      title: "客户编号",
                      width: 200,
                      slots: {
                        // 使用插槽模板渲染
                        default: "customerName_default",
                      },
                    },
                    {
                      field: 'pbgId',
                      title: '商品信息',
                      className:'mergeCell',
                      width: 200,
                      slots: {
                        // 使用插槽模板渲染
                        default: 'for_default',
                      }
                    },
                    {
                      field: 'goodsRemark',
                      title: '商品备注',
                      className:'mergeCell',
                      width: 100,
                      slots: {
                        // 使用插槽模板渲染
                        default: 'for_default2',
                      }
                    },
                    {
                      field: 'inquiryRemark',
                      title: '询盘备注',
                      width: 150,
                      slots: {
                        // 使用插槽模板渲染
                        default: 'for_default5',
                      }
                    },
                    {
                      field: 'receiveAddress',
                      title: '收货信息',
                      width: 150,
                      slots: {
                        // 使用插槽模板渲染
                        default: 'for_default3',
                      }
                    },

                    {
                      field: 'billTakeNum',
                      title: '提货数量',
                      width: 100,
                      formatter ({ cellValue }) {
                        return  cellValue + '吨'
                      }
                    },
                    {
                      field: 'takeWarehouse',
                      title: '提货仓库',
                      width: 150,
                    },
                    {
                      field: 'takeAddress',
                      title: '提货地址',
                      width: 150,
                    },
                    {
                      field: 'takeTime',
                      title: '提货时间',
                      width: 150,
                    },
                    {
                      field: 'sendType',
                      title: '提货类型',
                      width: 150,
                    },
                    {
                      field: 'takeRemark',
                      title: '提货备注',
                      width: 150,
                      showOverflow:true,
                    },
                    {
                      field: 'warehouseRemark',
                      title: '仓库备注',
                      width: 150,
                      showOverflow:true,
                    },
                    {
                      field: 'purchaseOrderSn',
                      title: '采购合同号',
                      width: 150,
                    },
                    {
                      field: 'userRealName',
                      title: '业务员',
                      width: 100,
                    },
                    {
                      field: 'driverName',
                      title: '司机信息',
                      width: 150,
                      slots: {
                        // 使用插槽模板渲染
                        default: 'for_default6',
                      }
                    },
                    {
                      field: 'planFreight',
                      title: '运费',
                      width: 100,
                    },
                    {
                      field: 'deliverSn',
                      title: '发货单号',
                      width: 150,
                    },
                    {
                      field: 'planState',
                      title: '排货状态',
                      width: 100,
                      formatter ({ cellValue }) {
                        if(cellValue == 0){
                          return '待物流发货'
                        }else if(cellValue == 5){
                          return '已取消'
                        }else if(cellValue == 10){
                          return '发货中'
                        }else if(cellValue == 20){
                          return '待安排司机'
                        }else if(cellValue == 25){
                          return '待提货'
                        }else if(cellValue == 30){
                          return '待出库'
                        }else if(cellValue == 40){
                          return '已出库'
                        }
                      }
                    },
                    {
                      field: 'createdTime',
                      title: '创建时间',
                      width: 150,
                    },
                    {
                      field: 'createdUser',
                      title: '创建人',
                      width: 100
                    },
                    {
                      field: 'logisticsUserName',
                      title: '物流调度',
                      width: 100,
                    },
                    {
                      field: 'updatedTime',
                      title: '更新时间',
                      width: 150,
                    },
                    {
                      field: 'cancelType',
                      title: '取消类型',
                      width: 100,
                    },
                    {
                      field: 'cancelReason',
                      title: '取消原因',
                      width: 150,
                    },{
                      field: 'lossFreight',
                      title: '运费损失',
                      width: 100,
                    }, {
                      field: 'orderRemark',
                      title: '结算方式',
                      fixed:'right',
                      // showOverflow:'title',
                      width: 230,
                      slots: {
                        default: 'for_default10',
                      },
                    },
                    {
                      field: '',
                      title: '收货确认函',
                      width: 100,
                      fixed:'right',
                      slots: {
                        default: 'for_default9',
                      },

                    },

                    {
                      field: '',
                      title: '操作',
                      width: 100,
                      fixed:'right',
                      slots: {
                        default: 'for_default7',
                      },

                    },
                  ],
                  data:[],
                },
                drawer:false,
                goodsLoading:false,
                list:[],
                formPage:'',
                billTypeList:[{key:'purchaseOrder',name:'采购单'},{key:'saleOrder',name:'销售单'},{key:'agentProcess',name:'代加工单'}],
            }
        },
        computed: {
            ...mapGetters([
                'name',
                'mobile',
                'userId'
            ]),
        },
        components : {
          sendGoods:sendGoods,
          sourceGoods:sourceGoods,
          dischargingInfo:dischargingInfo,
          printdischarging:printdischarging,
          cancelShipment:cancelShipment,
          confirmOut:confirmOut,
          logisticsConfirmsDelivery:logisticsConfirmsDelivery,
        },
        created() {
            this.init();
            // let now = new Date().getTime();
            // let endTime = now+60*60*24*1000*2;
            // let startTime = endTime - 60*60*24*1000*30;
            // let startDate = formatDate(new Date(startTime), 'yyyy-MM-dd');
            // let endDate = formatDate(new Date(endTime), 'yyyy-MM-dd');
            // this.listQuery.date = [startDate,endDate];
            // this.getList();
            // this.getUserOptionList();
        },
        filters: {
            formatCreateTime(time) {
                if(time){
                    let date = new Date(time);
                    return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
                }else{
                    return '--'
                }
            },
            fifitem(item){
              return item.goodsName+'/'+item.goodsSn
            },
            shipType(val,takeNum){
                if(parseFloat(val) == 0){
                    return '未发货'
                }else if(parseFloat(val) < parseFloat(takeNum)){
                    return '部分发货'
                }else{
                    return '已发货'
                }
            },
            fifState(val){
              if(val == 0){
                return '待物流发货'
              }else if(val == 10){
                return '发货中'
              }else if(val == 20){
                return '待安排司机'
              }else if(val == 30){
                return '待出库'
              }else if(val == 40){
                return '已出库'
              }else if(val == 5){
                return '已取消'
              }
            },
        },
        methods:{
          openUrl(item){
            window.open(item)
          },
          init(){
            if(window.location.href.indexOf('saleContractDetails') != -1){
              this.formPage = 'sale';
              this.listQuery.isMy = 1
            }else{
              this.listQuery.isMy = 0
            }
            let now = new Date().getTime();
            let endTime = now+60*60*24*1000*2;
            let startTime = endTime - 60*60*24*1000*30;
            let startDate = formatDate(new Date(startTime), 'yyyy-MM-dd');
            let endDate = formatDate(new Date(endTime), 'yyyy-MM-dd');
            this.listQuery.date = [startDate,endDate];
            this.getList();
            this.getUserOptionList();
            if(this.$route.query.dataPlanState){
              this.listQuery.planState = this.$route.query.dataPlanState
            }
            if(this.$route.query.dataDate){
              this.listQuery.date = this.$route.query.dataDate
            }
            console.log("href",window.location.href)


          },
          //联想商品
          remoteMethod(key){
            this.goodsLoading = true;
            getCrmGoodsList({keyword:key}).then((res)=>{
              this.list = res;
              this.goodsLoading = false;
            }).catch(()=>{
              this.goodsLoading = false;
            })
          },
          //刷新页面
          refresh(billId){
            this.getList();
            if(this.drawer){
              this.$refs.dischargingInfo.init(billId,this.formPage)
            }
          },

          //显示确认出库
          showDialogVisible(item){
            this.$refs.confirmOut.showDialogVisible(item);
          },

          //显示打印
          showPrint(item,checked){
            this.$refs.printdischarging.showPrint(item.billId,checked);
          },

          //确认提货
          confirmTiHuo(item){
            this.$confirm('请输入运费', '确认已提货?', {
              dangerouslyUseHTMLString:true,
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              showInput:true,
              inputPlaceholder:'请输入运费',
              inputValue:item.planFreight,
            }).then(({ value }) => {
              console.log("value",value)
              checkBillTake({billId:item.billId,planFreight:value}).then(()=>{
                this.refresh(item.billId)
                this.$message({
                  type: 'success',
                  message: '操作成功!'
                });
              })
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消操作'
              });
            });
          },

          //确认入库
          confirmWarehousing(item){
            this.$confirm('确认将此记录变成已入库?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              checkStockIn({billId:item.billId}).then(()=>{
                this.refresh(item.billId)
                this.$message({
                  type: 'success',
                  message: '操作成功!'
                });
              })
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消操作'
              });
            });
          },

          //取消发货
          cancelDeliver(item){
            this.$confirm('确认取消此次发货?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              cancelGoodsDeliver({billId:item.billId}).then(()=>{
                this.refresh(item.billId)
                this.$message({
                  type: 'success',
                  message: '操作成功!'
                });
              })

            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消操作'
              });
            });
          },

          //显示物流确认发货
          showDialogVisible4(item,title){
            this.$refs.logisticsConfirmsDelivery.showDialogVisible4(item,title);
          },


          //打开详情
          toInfo(item){
            this.drawer = true;
            setTimeout(()=>{
              this.$refs.dischargingInfo.init(item.billId,this.formPage)
            },300)
          },

          topurchasePickUp(){
            this.$router.push({name:'purchasePickUp'})
          },

          //显示取消排货
          showCancelForm(billId){
            this.$refs.cancelShipment.showCancelForm(billId)
          },

            //物流发货
            showSendGoods(item){
              this.$refs.sendGoods.showPop(item)
            },

            //显示货源
            showHoYuan(item){
                this.$refs.sourceGoods.showPop(item,'0')
            },

            //获取员工下拉选项
            getUserOptionList(){
                getOrderUsersList().then((res)=>{
                    this.userOptionList = res;
                })
            },

            //选择员工名称
            handleSelectUserName(key,item){
                this.listQuery[key] = item.userId;
            },
            //客户名称输入匹配
            querySearch(queryString){
              getCustomerOption({keywords:queryString}).then((res)=>{
                this.querySearchList = res;
              })
            },

            /**
             * 切换选择状态
             */
            handleSelect(key, keyPath){
              this.listQuery.planState = key;
              this.handleSearchList();
            },
            handleSizeChange(val){
                this.listQuery.pageNum = 1;
                this.listQuery.pageSize = val;
                this.getList();
            },
            handleCurrentChange(val){
                this.listQuery.pageNum = val;
                this.getList();
            },

            handleSearchList(){
                this.listQuery.pageNum = 1;
                this.getList();
            },

            //获取列表
            getList() {
                this.listLoading = true;
                planGoodsListScheduled(this.listQuery).then(response => {
                    this.gridOptions.data = response.list;
                    this.count = response.count;
                    this.listLoading = false;
                }).catch(()=>{
                    this.listLoading = false;
                });
            },

        },
    }
</script>

<style  lang="scss">
    .mergeCell .vxe-cell{padding:0;}
    .mergeDiv{
      padding-left:10px;
      padding-right:10px;
      border-bottom:1px solid #e8eaec;
      min-height: 36px;
    }

    .mergeDiv:last-child{
      border-bottom: 0;
    }
</style>
